package com.sz.flowable.controller;

import com.sz.core.common.entity.ApiResult;
import com.sz.flowable.dto.CompleteTaskDTO;
import com.sz.flowable.dto.StartProcessDTO;
import com.sz.flowable.dto.TaskDTO;
import com.sz.flowable.service.BpmnService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yinan
 */
@Tag(name = "流程引擎")
@RestController
@RequestMapping("/flowable")
@RequiredArgsConstructor
@Slf4j
public class BpmnFlowableController {

    private final BpmnService bpmnService;

    @Operation(summary = "流程启动")
    @PostMapping("/startProcess")
    public ApiResult<String> startProcess(@RequestBody StartProcessDTO dto) {
        return ApiResult.success(bpmnService.startProcess(dto));
    }

    @Operation(summary = "待办列表")
    @GetMapping("/todo")
    public ApiResult<List<TaskDTO>> todoList(@RequestParam(required = false) String username) {
        return ApiResult.success(bpmnService.getTodoList(username));
    }

    @Operation(summary = "任务完成")
    @PostMapping("/complete")
    public ApiResult<Void> complete(@RequestBody CompleteTaskDTO dto) {
        bpmnService.completeTask(dto);
        return ApiResult.success();
    }
}
